/**
 * 文件名称:  MenuDao.java
 * 所属版权:  ChinaStar Technologies Co., Ltd. Copyright 2010-2021, All rights reserved
 * 简单描述:  <描述>
 * 修改作者:  xdli
 * 修改时间:  2012-6-20
 * 修改内容:  <修改内容>
 */
package com.chinastar.iweb.menu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.chinastar.iweb.common.jdbc.DataType;
import com.chinastar.iweb.common.jdbc.ParameType;
import com.chinastar.iweb.common.jdbc.StarSupport;
import com.chinastar.iweb.menu.domain.MenuBean;
import com.chinastar.iweb.user.domain.UserBean;

/**
 * MenuDao
 *  
 * @author  xdli
 * @version 2012-6-20
 * @see     MenuDao
 * @since   1.0
 */
public class MenuDao
{
    private StarSupport starSupport = null;

    public StarSupport getStarSupport()
    {
        return starSupport;
    }

    public void setStarSupport(StarSupport starSupport)
    {
        this.starSupport = starSupport;
    }
    
    /**
     * 
     * Load MenuTree
     *
     * @param userBean user Objectn 
     * @param nodeid menutree node number
     * @return menutree's array
     */
    public List<MenuBean> loadMenu(UserBean userBean, String nodeid)
    {
        try
        {
            starSupport.setProcedure("p_loadmenutree(:i_usernum,:i_node,:o_ret,:o_cursor)");
            starSupport.addParame("i_usernum", DataType.VARCHAR, userBean.getUserNum(), ParameType.PARAME_IN);
            starSupport.addParame("i_node", DataType.VARCHAR, nodeid, ParameType.PARAME_IN);
            starSupport.addParame("o_ret", DataType.INTEGER, null, ParameType.PARAME_IN);
            starSupport.addParame("o_cursor", DataType.CURSOR, null, ParameType.PARAME_IN);
            starSupport.execute();
            if (starSupport.getInt("o_ret") == 0)
            {
                return toResultSet(starSupport.getDataSet("o_cursor"));
            }
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        return null;
    }
    
    /**
     * 
     * toResultSet
     *
     * @param resultSet
     * @return
     */
    private List<MenuBean> toResultSet(ResultSet resultSet)
    {
        List<MenuBean> menuList = new ArrayList<MenuBean>();
        MenuBean menuBean = null;
        try
        {
            while (resultSet.next())
            {
                menuBean = new MenuBean();
                
                menuList.add(menuBean);
            }
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        return menuList;
    }
}
